package com.h4313.ghome.ui.dialog;

import java.lang.ref.WeakReference;
import java.util.Calendar;

import android.app.Dialog;
import android.app.DialogFragment;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.widget.TimePicker;

public class HourPickerDialog extends DialogFragment implements
		TimePickerDialog.OnTimeSetListener {

	public static interface TimePickerCallback {
		public void onTimeSet(int hour, int min);
	}
	
	public static class MorningConf {
		public int hourCoffee, minCoffee, hourGCalendar, minGCalendar;
	}
	
	private WeakReference<TimePickerCallback> mCallback = new WeakReference<TimePickerCallback>(null);
	
	public HourPickerDialog(TimePickerCallback callback) {
		mCallback = new WeakReference<TimePickerCallback>(callback);
	}
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// Use the current time as the default values for the picker
        final Calendar c = Calendar.getInstance();
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);

        // Create a new instance of TimePickerDialog and return it
        TimePickerDialog dial = new TimePickerDialog(getActivity(), this, hour, minute,
                true);
        return dial;
	}

	@Override
	public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

		if (mCallback.get() != null) {
			mCallback.get().onTimeSet(hourOfDay, minute);
		}
		//mOrigin.setText(UIUtils.formatHour(hourOfDay, minute));
	}
}
